var BALANCE_URL = "http://39.108.226.96/HSZWeb/GetTotalBalance";

$(function () {
    try {
        var info = getUserInfo();
        if (info.userinfo) {
            $("#error").hide().next().show();
            $("#username").prepend(info.userinfo.username);


            $("main .content .tab-content>div.tab-pane").each(function (index, ele) {
                var src = $(ele).find("iframe").attr("src");
                if (src) {
                    $(ele).find("iframe").attr("src", src + info.extra);
                }
            });

        }
    } catch (e) {
        $("#error").show().next().hide();
    }

    $("#balanceBtn").on('click', function (e) {
        $.ajax({
            url: BALANCE_URL,
            type: "post",
            dataType: "json",
            success: function (res) {
                $("#balanceModal #balanceInput").val(res.balance);
                $("#balanceModal #lastpaidInput").val(res.lastpaid);
                $("#balanceModal").modal('toggle');
            },
            error: function (e) {
                alert("请求超时");
            }
        });
    });

    function getUserInfo() {
        var url = location.href;
        var extra = url.substring(url.indexOf("?"));
        var userinfo = JSON.parse(decodeURI(url.substring(url.indexOf("userInfo=") + 9)));
        return {
            extra: extra,
            userinfo: userinfo
        }
    }
});